class Solution2 {
    public static void main(String[] args) {
        String s = "pwwkew" ;
        System.out.println(lengthOfLongestSubstring(s));
    }
    public static int lengthOfLongestSubstring(String s) {
        int len = s.length() ;
        int max = 0 ;
        int[] dp = new int[128] ;
        char[] arr = s.toCharArray() ;
        for(int i = 0 , j=0 ;  j < len ; ){
            dp[arr[j]] ++ ;
            if(dp[arr[j]] == 1){
                j ++ ;
            }else{
                dp[arr[i]] --  ;
                i ++ ;
                j ++ ;
            }
            max = Math.max(max, j-i) ;
        }
        return max ;
    }
}